package acwing.mergedInterval;

import com.sun.org.apache.bcel.internal.generic.NEW;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

public class mergedInterval {
    static int[] arr;
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static List<int[]> list = new ArrayList<>();
    public static void main(String[] args) throws IOException {
        String s = br.readLine();
        int n = Integer.parseInt(s);
        String[] s1 = br.readLine().split(" ");
        while(n-- != 0){
            int l = Integer.valueOf(s1[0]);
            int r = Integer.valueOf(s1[1]);
            // 存储l和r
            arr = new int[2];
            arr[0] = l;
            arr[1] = r;
            list.add(arr);
        }
        // 排序
        list.sort(new Comparator<int[]>() {
            @Override
            public int compare(int[] o1, int[] o2) {
                return o1[0] - o2[0];
            }
        });
        int res = 0;
        // 定义右端点
        int r = Integer.MIN_VALUE;
        // 遍历集合
        for (int[] ints : list) {
            // 如果下个数组的左端点在右端点的右边
            if (ints[0] > r) res++;
            // 更新右端点
            r = Math.max(ints[1], r);
        }
        System.out.println(res);
        br.close();
    }
}
